package org.example.net;

import lombok.SneakyThrows;

import java.io.InputStream;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

/**
 * @Auther:Liu
 * @Testname:DemoB2
 * @Date:2025/8/27 17:25
 */
public class DemoB2 {
    @SneakyThrows
    public static void main(String[] args) {
        Socket socket = new Socket("127.0.0.1", 8889);
        System.out.println("通讯已开启");
        InputStream inputStream = socket.getInputStream();
        byte[] bytes = new byte[1024];
       while (true){
           int len = inputStream.read(bytes);
           String s = new String(bytes, 0, len, StandardCharsets.UTF_8);
           System.out.println(s);
           if ("bye".equals(s)) {
               break;
           }
       }
    }
}
